﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RH.Common.Extensions;
using RH.Domain;
using RH.Web.ViewModels;
using RH.Web.Utility;
using AutoMapper;
using System.Data;
using RH.Web.ViewModels.UtilityModels;

namespace RH.Web.Controllers
{
    public class ContentController : BaseController
    {
		private AppEntities _Context = new AppEntities();
        
		#region Constructors
		public ContentController()
		{
		}

        public ContentController(UserViewModel currentUser)
			: base(currentUser)
        {
        }
		#endregion Constructors

		#region Action Methods

        public ActionResult ViewContent(string contentUrl)
        {
            //string seoUrl = contentUrl.ToSeoUrl();

            Content entity = null;
            entity = _Context.Contents.FirstOrDefault(P => P.Url == contentUrl);
            ContentViewModel viewModel = Mapper.Map<Content, ContentViewModel>(entity);

            ViewBag.SearchKey = contentUrl;

            return View(viewModel);

            
            ///
            ///Old Way
            ///
            
            ////TODO: Need to Change this code to use the Entity Framework. And the View should be a Typed View
            ////FIXME: Rabbani, Please Correct following implementation. And get the content filtered by contentUrl from the Content collection
            ////We are using custom made stored procedures to populate list pages only.
            //UtilityDAO dao = new UtilityDAO();
            //RH.Domain.DbParameter[] parameters = new[]{
            //    new RH.Domain.DbParameter("@ContentID", (contentUrl=="AboutUs")? ConfigReader.AboutUs : 
            //                                                (contentUrl=="OurServices")? ConfigReader.OurServices : 
            //                                                (contentUrl=="FAQ")? ConfigReader.FAQ : 
            //                                                (contentUrl=="ContactUs")? ConfigReader.ContactUs : 0)
            //};
            //DataSet ds = dao.GetDataSet(DbObject.SP.GET_CONTENT, parameters, true);
            //ViewBag.ContentTitle = ds.Tables[0].Rows[0]["Title"].ToString();
            //ViewBag.Summery = ds.Tables[0].Rows[0]["Summery"].ToString();
            //ViewBag.Description = ds.Tables[0].Rows[0]["Description"].ToString();

            //return View();
        }
		
		#endregion Action Methods
		
		#region Helper Methods

        #endregion			
    }
}
